define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'rate/admin/index',
                    add_url: 'rate/admin/add',
                    edit_url: 'rate/admin/edit',
                    del_url: 'rate/admin/del',
                    multi_url: 'rate/admin/multi',
                }
            });

            var table = $("#table");


            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},

                        {field: 'username', title: __('Username')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'email', title: __('Email')},
                        {field: 'status', title: __("Status"), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {

                                return Table.api.formatter.operate.call(this, value, row, index);
                            }}
                    ]
                ]

            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            //绑定点击时间
            $("#choose-rate").on("click", "input", function () {
                var radio_data = $(this).val();
                if (radio_data == 0) {
                    $('#rate-area-list').hide();
                } else {
                    $('#rate-area-list').show();
                }
            });
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});
